<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ include file="/WEB-INF/public/head.jspf"%>	
<style type="text/css">
	form div{
		margin:5px;
	}
</style>
<script type="text/javascript">
$(function(){
		//iframe中的dg对象
		var dg = parent.$("iframe[title='商品管理']").get(0).contentWindow.$("#dg");
		//完成数据的回显
		var rows = dg.datagrid("getSelections");
		//alert(rows[0].id+""+rows[0].type+""+rows[0].hot);
		//远程加载
		$('#cc').combobox({    
		    url:'category_query.action',    
		    valueField:'id',    
		    textField:'type',
		    panelHeight:'auto',
		    panelwidth:120,
		    width:120,
		    value:'请选择商品类别',
		    editable:false  
		});
		$("input[name=name]").validatebox({
			required:true,
			missingMessage:'请输入商品名称'
		});
		$("input[name=price]").numberbox({
			required:true,
			missingMessage:'请输入商品价格',
			min:0,
			precision:2,
			//前缀
			prefix:'$'
		});
		$("textarea[name=remark]").validatebox({
			required:true,
			missingMessage:'请输入商品的简单描述'
		});
		$('#ff').form('load',{
			id:rows[0].id,
			name:rows[0].name,
			price:rows[0].price,
			//jQuery中不支持.要使用加''
			'category.id':rows[0].category.id,
			commend:rows[0].commend,
			open:rows[0].open,
			remark:rows[0].remark,
			xremark:rows[0].xremark
		});
		$("input[name=name]").validatebox({
			required:true,
			missingMessage:'请输入类别名称'
		});
		//窗体弹出默认禁用
		$("#ff").form("disableValidation");
		//注册button的事件
		$("#submit").click(function(){
			$("#ff").form("enableValidation");
			//如果验证成功提交数据
			if($("#ff").form("validate")){
				//$.messager.progress();	// 显示进度条
				$('#ff').form('submit', {
					url: 'product_update.action',
					success: function(){
						//$.messager.progress('close');	// 如果提交成功则隐藏进度条
						//关闭窗体
						parent.$("#win").window("close");
						//刷新页面
						//aindex--->iframe--->dg
						//parent.$("iframe[title='分类管理']").contents().find("#dg").datagrid("reload");
						dg.datagrid("reload");
					}
				});
			}
		});
		$("#reset").click(function(){
			$('#cc').combobox({    
		    url:'category_query.action',    
		    valueField:'id',    
		    textField:'type',
		    panelHeight:'auto',
		    panelwidth:120,
		    width:120,
		    value:'请选择商品类别',
		    editable:false  
		});
		$('#ff').form('load',{
			id:rows[0].id,
			name:rows[0].name,
			price:rows[0].price,
			//jQuery中不支持.要使用加''
			'category.id':rows[0].category.id,
			commend:rows[0].commend,
			open:rows[0].open,
			remark:rows[0].remark,
			xremark:rows[0].xremark
		});
		});
	});
</script>
</head>

<body>
	<form title="添加商品" id="ff" method="post" enctype="multipart/form-data">   
    <div>   
        <label>商品名称:</label>   
        <input type="text" name="name"/>   
    </div>   
    <div>   
        <label>商品价格:</label>   
        <input type="text" name="price"/>   
    </div>   
   <!--  <div>   
        <label>图片上传:</label>   
        <input type="file" name="upload"/>   
    </div>  -->
    <div>
    	<label>所属类别:</label>
    	<select id="cc" name="category.id"></select>
    </div>  
    <div>   
        <label>加入推荐:</label>   
		推荐:<input type="radio" name="commend" value="true"/>
		非推荐:<input type="radio" name="commend" value="false" checked="checked"/>
    </div> 
    <div>   
        <label>是否有效:</label>   
		上架:<input type="radio" name="open" value="true"/>
		下架:<input type="radio" name="open" value="false" checked="checked"/>
    </div> 
    <div>
    	<label>简单描述:</label>
    	<textarea rows="4" cols="40" name="remark"></textarea>
    </div>
    <div>
    	<label>详细描述:</label>
    	<textarea rows="8" cols="40" name="xremark"></textarea>
    </div>
    <div>
	    <input type="hidden" name="id"/> 
	    <a id="submit" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">更改</a>  
	    <a id="reset" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">重置</a> 
    </div>
</form>
</body>
</html>